package cate.game.play.buff.h;

import cate.common.table.d.GD;
import cate.common.table.d.GDSkill;
import cate.game.play.buff.BuffHandler;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.util.FighterFilter;

/**
 * 攻击时满足特定条件添加buff
 */
public class 攻击添加buffBH extends BuffHandler {

	private PlayCfgArgs args;

	private Boolean 暴击;

	private byte 目标基准;

	private int 概率;

	private int buffTid;

	private int 人数限制;

	//暴击=1&目标基准=1&概率=10000&buff=？？&人数限制=-1
	@Override
	public void parse(String code) {
		args = new PlayCfgArgs(code);
		暴击 = args.getBoolean("暴击", null);
		目标基准 = args.getByte("目标基准", GDSkill.Base.CASTER);
		概率 = args.getInt("概率", GD.W_10000);
		buffTid = args.getInt("buff", 0);
		人数限制 = args.getInt("人数限制", -1);
	}

	private int addNum;

	@Override
	public void afterOneAttack(SkillActionCtx action, byte nature, long totalDamage, boolean strike, Fighter target) {
		if (暴击 != null && 暴击 != strike) {
			return;
		}
		if (人数限制 > 0 && addNum >= 人数限制) {
			return;
		}
		if (FighterFilter.test(args, buff.owner, target)) {
			getFighterBySrc(目标基准, action.getActor(), target).buff.tryAddByTid(action, action.getActor(), buffTid, 概率);
			addNum++;
		}
	}

	@Override
	public void onOwnerMoveDone(MoveCtx move, TimeActionCtx action) {
		addNum = 0;
	}
}
